package com.lft.freshordering.controller;

import com.lft.freshordering.entity.Gocar;
import com.lft.freshordering.entity.VO.CartShopVO;
import com.lft.freshordering.response.R;
import com.lft.freshordering.service.IGocarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import java.util.List;

@RestController
@RequestMapping("/gocar")
public class GocarCountroller {

    @Autowired
    private IGocarService gocarService;

    @RequestMapping("/insertGocar")
    public R insertGocar(@RequestBody Gocar gocar) {
        System.out.println(gocar);
        String s = gocarService.insertGocar(gocar);
        return R.success(s);
    }

    @RequestMapping("/selectbyuid/{uid}")
    public R selectbyuid(@PathVariable Integer uid) {
        List<CartShopVO> selectbyuid = gocarService.selectbyuid(uid);
        return R.success(selectbyuid);
    }

    //下单
    @RequestMapping("/addzhangdan")
    public R insertzhnagdan(@RequestBody Map map) {
        System.out.println(map);
        gocarService.addzhangdan(map);
        return R.success("下单成功");
    }

    //删除购物车中的商品
    @RequestMapping("/delectbyid")
    public R delectbyid(@RequestBody Map map) {
        Integer i =gocarService.deletebyids(map);
        if (i>0){
            return R.success("删除成功");

        }else {
            return R.error(500,"删除失败");

        }
    }

}
